

<script type="text/javascript">
	var q_id = '', date_from = '', date_to = '';
	
	$(function(){
		$("#generate").click(function(){generate();});
		$("#graphic-container .button").click(function(){ExportMyChart();});
	});
	
	function generate(){
		if($("#dateFrom-value").val() != '' && $("#dateTo-value").val() != '' ){
			q_id = $(".question_option:selected").val(),
			date_from = $("#dateFrom-value").val(),
			date_to = $("#dateTo-value").val();
			
			var param="%2F"+date_from+"%2F"+date_to+"%2F"+q_id;
			
			swfobject.embedSWF(
			  "<?= base_url();?>assets/swf/open-flash-chart.swf", "smile_chart",
			  "600", "300",
			  "9.0.0", "expressInstall.swf",
			  {"data-file":"<?= urlencode(base_url());?>admin%2Fstatistic%2Fget_data_pie"+param}
			);
			
		}else{
			alert ("Harap mengisi rentang waktu yang ingin dipantau.");
		}
	}
	
	function ExportMyChart(debug) {
		//window.print();
		var url = "<?= base_url();?>admin/statistic/ofc_upload_image/"+q_id+"/"+date_from+"/"+date_to;
		var ofc = findSWF("smile_chart");
		x = ofc.post_image( url, 'done', debug );
	}
	
	
	function findSWF(movieName) {
		if (navigator.appName.indexOf("Microsoft")!= -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	}
	
	function done(id){
		//window.location.href='';
		alert("Finished upload. Id:"+id);
	}
</script>

<div id="content">
    <div class="post">
        <h2 class="title">Monitoring Index Pelayanan Plasa</h2>
        <div style="clear: both;">&nbsp;</div>
        <div class="entry">
            <form>
                Kriteria :&nbsp;
                <select id="question_selector">
                        <?php
                                foreach($questions as $key => $val){
                                        echo '<option class="question_option" id="quest-'.$val['question_id'].'" value="'.$val['question_id'].'">'.$val['content'].'</option>';
                                }
                        ?>
                </select>
                
                &nbsp;Mulai :&nbsp;<input class='monthpicker' id='dateFrom' readonly="readonly"/><input type="hidden" id="dateFrom-value"/>
                &nbsp;Selesai :&nbsp;<input class='monthpicker' id='dateTo' readonly="readonly"/><input type="hidden" id="dateTo-value"/>		
				<br>
                <div class="center"><input class="button" type="button" id="generate" value="Buat Statistik"/></div>
            </form>      
        </div>
    </div>
</div>

<div id="content">
	<div id="graphic-container" class="chart-div" align="center">
		<div id="smile_chart"></div>
		<input class="button" type="button" style="margin-top: 10px;display:block;" onclick="ExportMyChart(true);" value="Print Report"/>
	</div>
</div>